<?php
namespace App\Controller\Admin;

use App\Constants\ErrorCode;
use App\Middleware\AdminMiddleware;
use App\Model\QmGameProclamation;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\PostMapping;


#[Controller(prefix: '/admin/GameProclamation'), Middleware(AdminMiddleware::class)]
class GameProclamationController extends BaseController
{

    /**
     * 获取公告列表
     * @return array
     */
    #[GetMapping(path: 'index')]
    public function index(): array
    {
        $limit = $this->request->query('size', config('apiadmin.admin_list_default'));
        $listObj = QmGameProclamation::query()->orderByDesc('id')->paginate((int)$limit);

        return $this->buildSuccess([
            'list' => $listObj->items(),
            'count' => $listObj->total()
        ]);
    }

    /**
     * 新增分类
     * @return array
     */
    #[PostMapping(path: 'add')]
    public function add(): array {
        $obj = new QmGameProclamation();
        $obj->proclamation = $this->request->post('proclamation');
        $obj->save();
        return $this->buildSuccess();
    }

    /**
     * 编辑分类
     * @return array
     */
    #[PostMapping(path: 'edit')]
    public function edit(): array {
        $obj = QmGameProclamation::find($this->request->post('id'));
        $obj->proclamation = $this->request->post('proclamation');
        $obj->save();
        return $this->buildSuccess();
    }
    /**
     * 删除分类
     * @return array
     */
    #[GetMapping(path: 'del')]
    public function del(): array {
        QmGameProclamation::destroy($this->request->query('id'));
        return $this->buildSuccess();
    }
}
